using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace OpenScrum.db
{
    public class Project
    {
        #region Properties

        public int ProjectId { get; set; }
        [Required]
        public string Name { get; set; }
        public string Description { get; set; }   
        public DateTime CreatedDate { get; set; }

        #endregion  

        #region Navigation Properties

        public virtual ICollection<Swimlane> Swimlanes { get; set; }        
        public virtual ICollection<TeamMember> TeamMembers { get; set; }
        public virtual ICollection<BacklogItem> BacklogItems { get; set; }

        #endregion

        #region Constructor

        public Project()
        {
            CreatedDate = DateTime.Now;
        }

        #endregion  
    }

    class ProjectConfiguration : EntityTypeConfiguration<Project>
    {
        internal ProjectConfiguration()
        {
            this.HasMany(s => s.Swimlanes)
                .WithMany(p => p.Projects)
                .Map(mc =>
                         {
                             mc.MapLeftKey("ProjectId");
                             mc.MapRightKey("SwimlaneId");
                             mc.ToTable("ProjectSwimlane");
                         });

            this.HasMany(p => p.TeamMembers)
                .WithMany(t => t.Projects)
                .Map(mc =>
                         {
                             mc.MapLeftKey("ProjectId");
                             mc.MapRightKey("TeamMemberId");
                             mc.ToTable("ProjectTeamMember");
                         });
        }
    }
}